﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevDemo.Entity;

namespace DevDemo.UploadFile
{
    public partial class Upload_ProjectAdd : DevExpress.XtraEditors.XtraForm
    {
        public List<ProjectModel> projects = new List<ProjectModel>();

        public ProjectModel CheckedProject = new ProjectModel();

        public string str_state = string.Empty;

        public Upload_ProjectAdd()
        {
            InitializeComponent();
        }

        /// <summary>
        /// OK
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_OK_Click(object sender, EventArgs e)
        {
            if (CheckedProject != null && str_state == "AddSonItem")
            {
                projects.Add(new ProjectModel
                {
                    PROJECTPID = CheckedProject.PROJECTID,

                    PROJECTID = Guid.NewGuid().ToString(),

                    PROJECTNAME = "",

                    PROJECTEDITION = tb_ProjectEdition.Text.Trim(),

                    PROJECTREMARKS = tb_ProjectRemarks.Text.Trim(),

                    PROJECTCREATEDATE = DateTime.Now,

                    PROJECT_TYPE = 1
                });
            }
            else
            {
                string Project_ID = Guid.NewGuid().ToString();

                projects.Add(new ProjectModel
                {
                    PROJECTPID = "0",

                    PROJECTID = Project_ID,

                    PROJECTNAME = tb_ProjectName.Text.Trim(),

                    PROJECTEDITION = "1.0.0.0",// tb_ProjectEdition.Text.Trim(),

                    PROJECTREMARKS = tb_ProjectRemarks.Text.Trim(),

                    PROJECTCREATEDATE = DateTime.Now,

                    PROJECT_TYPE = 0
                });

                projects.Add(new ProjectModel
                {
                    PROJECTPID = Project_ID,

                    PROJECTID = Guid.NewGuid().ToString(),

                    PROJECTNAME = "",

                    PROJECTEDITION = tb_ProjectEdition.Text.Trim(),

                    PROJECTREMARKS = tb_ProjectRemarks.Text.Trim(),

                    PROJECTCREATEDATE = DateTime.Now,

                    PROJECT_TYPE = 1
                });
            }

            DialogResult = DialogResult.OK;

            Close();
        }

        /// <summary>
        /// Close
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Upload_ProjectAdd_Load(object sender, EventArgs e)
        {
            if (CheckedProject != null && str_state == "AddSonItem")
            {
                tb_ProjectName.Text = CheckedProject.PROJECTNAME;

                tb_ProjectName.Enabled = false;

                tb_ProjectEdition.Text = "";
            }

            if (CheckedProject != null && str_state == "GetProjectInfo")
            {
                tb_ProjectName.Text = CheckedProject.PROJECTNAME;

                tb_ProjectName.Enabled = true;

                tb_ProjectEdition.Text = CheckedProject.PROJECTEDITION;

                tb_ProjectRemarks.Text = CheckedProject.PROJECTREMARKS;
            }
        }
    }
}